import axios from "axios";
import message from "@/utils/message";
import router1 from "@/router";
import Vue from "vue";
axios.interceptors.request.use(config=>{
    console.log(config.headers["token"]);
    if(localStorage.getItem('token')!=null){
        config.headers["token"] = localStorage.getItem('token');

    }
    return config;
})
axios.interceptors.response.use(
    async (response)=>{
        const code = response.data.code;
        if(code == 40101){

            // 未登录
            await this.$router.replace('/')
        }else if(code == 40100){
            // 无权限
            await router1.push('/userhome');
        }else if(code == 40102){
            // token被修改
            await this.$router.replace('/');
        }
        return response;
    }
)